/*
 * @Author: myw
 * @Email: 516378746@qq.com
 * @Date: 2020-03-05 16:45:54
 * @Descripttion: 移库入库服务
 */
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs';
import { SubwarehouseManageService } from '../../basedata-manage/subwarehouse-manage/subwarehouse-manage.service';
import { DictionaryManageService } from 'src/app/system-manage/dictionary-manage/dictionary-manage.service';
import { SubmaterialManageService } from '../../basedata-manage/submaterial-manage/submaterial-manage.service';
import { MaterialRelationService } from '../../basedata-manage/material-relation/material-relation.service';

@Injectable({
    providedIn: 'root'
})
export class MovewareApplyService {

    private listUrl: string = "/api/movement/movementIn";
    private baseUrl: string = "/api/movement";
    private wareinUrl: string = "/api/movement/updateStatus"

    constructor(
        private http: HttpClient,
        private subwarehouseService: SubwarehouseManageService,
        private subMaterialService: SubmaterialManageService,
        private dictionaryService: DictionaryManageService,
        private materialRelationService: MaterialRelationService
    ) { }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 13:57:49
     * @Descripttion: 获取移库入库列表数据
     * @Return: 
     */
    apiList(data): Observable<any> {
        let _dataJson = {
            params: {
                ...data,
                fromStorehouse: !data.fromStorehouse ? "" : data.fromStorehouse,
                page: data.page - 1
            }
        }
        return this.http.get(this.listUrl, _dataJson)
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 13:57:33
     * @Descripttion: 获取所有源仓库数据
     * @Return: 
     */
    apiSourceHouse(): Observable<any> {
        return this.subwarehouseService.getKFAllList();
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 13:57:16
     * @Descripttion: 获取物料数据
     * @Return: 
     */
    apiSubMaterial(): Observable<any> {
        return this.subMaterialService.getAllMaterial({});
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 13:57:07
     * @Descripttion: 删除
     * @Return: 
     */
    apidel(data): Observable<any> {
        return this.http.delete(`${this.baseUrl}?id=${data.id}`)
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 13:56:11
     * @Descripttion: 根据物料编码获取相关库房列表
     * @Return: 
     */
    apiHouseByMateriId(materiId): Observable<any> {
        let _dataJson = {
            materialId: materiId
        }
        return this.materialRelationService.findWareByMaterialId(_dataJson)
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 14:58:19
     * @UseComponent: 
     * @Descripttion: 根据物料编码 库房ID 获取相关库区数据
     * @Return: 
     */
    apiAreaByMateriId(data): Observable<any> {
        let _dataJson = {
            ...data
        }
        return this.materialRelationService.findWareAreaByMaterialId(_dataJson);
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 15:34:18
     * @UseComponent: 
     * @Descripttion: 根据 库房编号，库区编号，物料编号，查询库存批次
     * @Return: 
     */
    apiBatchByMateriId(data): Observable<any> {
        let _dataJson = {
            ...data
        }
        return this.materialRelationService.findStockBatchByIds(_dataJson)
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 13:58:05
     * @Descripttion: 提交/入库
     * @Return: 
     */
    apiEditStatus(data): Observable<any> {
        let _dataJson = {
            ...data
        }
        return this.http.put(this.wareinUrl, _dataJson)
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-06 13:58:15
     * @Descripttion: 获取移库类型
     * @Return: 
     */
    apiChooseTypeList(type): Observable<any> {
        let _dataJson = {
            dictName: type
        }
        return this.dictionaryService.getDetailAll(_dataJson);
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-09 11:15:08
     * @UseComponent: 
     * @Descripttion: 新增入库
     * @Return: 
     */
    apiAdd(data): Observable<any> {
        let _dataJson = [
            ...data
        ]
        return this.http.post(this.baseUrl, _dataJson)
    }
    /**
     * @Author: myw
     * @Email: 516378746@qq.com
     * @Date: 2020-03-09 13:54:18
     * @UseComponent: 
     * @Descripttion: 编辑入库
     * @Return: 
     */
    apiEdit(data):Observable<any>{
        let _dataJson = {
            ...data
        }
        return this.http.put(this.baseUrl, _dataJson);
    }
}
